package com.mySchool.service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.mySchool.entity.*;
import com.mySchool.entity.DTO.CityHigherQueryRequest;
import com.mySchool.entity.DTO.CityHigherQueryResponse;
import com.mySchool.entity.DTO.CityInsertRequest;
import com.mySchool.entity.DTO.CityUpdateRequest;
import com.mySchool.mapper.*;
import com.mySchool.service.*;

import org.springframework.beans.factory.annotation.*;
import org.springframework.stereotype.*;
import org.springframework.util.CollectionUtils;

import java.util.List;

@Service
public class CityServiceImpl implements CityService {
    @Autowired
    private CityMapper cityMapper;


    @Override
    public void insert(CityInsertRequest param) {
        cityMapper.insert(param);
    }

    @Override
    public void delete(List<Integer> param) {
        if (CollectionUtils.isEmpty(param)) {
            throw new IllegalArgumentException("传入值为空");
        }
        cityMapper.deleteByIds(param);

    }

    @Override
    public void update(CityUpdateRequest param) {
        cityMapper.update(param);
    }

    @Override
    public PageResult<CityHigherQueryResponse> queryHigher(CityHigherQueryRequest param) {
        PageHelper.startPage(param.getPageRequest().getPageNo(), param.getPageRequest().getPageSize());

        List<CityHigherQueryResponse> list = cityMapper.queryHigher(param);
        Page<CityHigherQueryResponse> p = (Page<CityHigherQueryResponse>) list;

        return new PageResult<>(p.getTotal(), p.getResult());
    }

}
